home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-04 | 7.8 KB | 341 lines | [TEXT/MMCC] |
- //•-----------------------------------------------------------------•//
- //• Another old C source, brought back from the dead ---------------•//
- //• by Kenneth A. Long, at itty bitty bytes™ -----------------------•//
- //• Made to run on Think C™ on 7 April 1994 ------------------------•//
- //• Made to run on Code Warrior on 20 November 1994 ----------------•//
- //• kenlong@netcom.com ---------------------------------------------•//
- //•-----------------------------------------------------------------•//
-
- //o Written 11:22 am Aug 22, 1986
- //o by sdh@joevax.UUCP
- //o Posted to uiucdcsb:net.sources.mac.
- //o "source to rae demo"
-
- //o rae.c
- //o This is the demo "rae" originally written for blit terminals
- //o converted to the Macintosh in Aztec C version 1.06H
- //o Steve Hawley 8/22/86
-
- //o I can't vouch for the code for rae. It was copied directly.
- //o I only changed the system commands and initialization sequence.
-
- #include <quickdraw.h>
- #include <events.h>
- #include <osutils.h>
-
- #define HEIGHT 16
- #define WIDTH 16
- #define XMIN 0
- #define YMIN 0
- #define XMAX qd.screenBits.bounds.right
- #define YMAX qd.screenBits.bounds.bottom
- #define TOP YMIN
- #define BOT (YMAX-1)
-
- short ground[128];
- short X_pos;
-
- GrafPort myPort;
-
- //o This is the bits for the face that gets bounced around.
- //o the original rae used just circles.
-
- static unsigned char facebits[32] = {
- 0x07, 0xe0, 0x18, 0x18, 0x20, 0x04, 0x42, 0x42, 0x42, 0x42,
- 0x82, 0x41, 0x80, 0x01, 0x80, 0x01, 0x84, 0x21, 0x88, 0x11,
- 0x94, 0x29, 0x43, 0xc2, 0x40, 0x02, 0x20, 0x04, 0x18, 0x18,
- 0x07, 0xe0
- };
-
- WindowPtr raeWindow; //• Added by KAL.
- Rect windowBounds; //• Added by KAL.
-
- struct BitMap face;
-
- //• MBar show/hide stuff.
- RgnHandle mBarRgn, GrayRgn;
- short *mBarHeightPtr;
- short oldMBarHeight;
-
-
- //•-----------------------------------------------------------------•//
- //• Prototypes: ----------------------------------------------------•//
- //•-----------------------------------------------------------------•//
- void Hide_Menu_Bar (void);
- void Show_Menu_Bar (void);
- void Setup_Window (void);
- void Draw_It (short x, short y);
- short Friction_Decay (short v);
- void Frame_It (void);
- void main (void);
-
- //•-----------------------------------------------------------------•//
- void Hide_Menu_Bar (void)
- {
- Rect mBarRect;
-
- GrayRgn = GetGrayRgn ();
- mBarHeightPtr = (short *) 0x0BAA;
- oldMBarHeight = *mBarHeightPtr;
- *mBarHeightPtr = 0;
- mBarRect = qd.screenBits.bounds;
- mBarRect.bottom = mBarRect.top + oldMBarHeight;
- mBarRgn = NewRgn ();
- RectRgn (mBarRgn, &mBarRect);
- UnionRgn (GrayRgn, mBarRgn, GrayRgn);
- PaintOne (0L, mBarRgn);
- }
-
- //•-----------------------------------------------------------------•//
- void Show_Menu_Bar (void)
- {
- *mBarHeightPtr = oldMBarHeight;
- DiffRgn (GrayRgn, mBarRgn, GrayRgn);
- DisposeRgn (mBarRgn);
- }
-
- //•-----------------------------------------------------------------•//
- void Setup_Window (void)
- {
- SetRect (&windowBounds, 0, 0, XMAX, YMAX);
-
- raeWindow = NewWindow (0L, &windowBounds, "\p", true, noGrowDocProc, (WindowPtr) -1L, true, 0);
- FillRect (&windowBounds, &qd.black);
- SetPort (raeWindow);
- }
-
- //•-----------------------------------------------------------------•//
- void Draw_It (short x, short y)
- {
- short i;
- Rect trect, myRect;
-
- if (x < XMIN)
- x = XMIN + 8;
-
- //• TOP is 0, so if vert. is less then it's 8 down.
- if (y < TOP)
- y = TOP + 8;
-
- //• XMAX is screen.right, so if it's more then it's 8 left.
- if (x > XMAX)
- x = XMAX - 8;
-
- X_pos = x >> 3;
- if (y > ground[X_pos])
- y = ground[X_pos];
-
- SetRect (&trect, x - 12, y - 8, x + 4, y + 8);
- CopyBits (&face, &myPort.portBits, &face.bounds, &trect, srcXor, 0L);
- }
-
- //•-----------------------------------------------------------------•//
- short Friction_Decay (short v)
- {
- if (v == 0)
- return (v);
- if (v > 0)
- return (v - 1 - (v >> 3));
-
- return (v + 1 - (v >> 3));
- }
-
- //•-----------------------------------------------------------------•//
- void Frame_It ()
- {
- PenPat (&qd.white);
- MoveTo (XMIN, YMIN);
- LineTo (XMIN, YMAX -1);
- MoveTo (XMIN, YMAX -1);
- LineTo (XMAX -1, YMAX -1);
- MoveTo (XMAX -1, YMAX -1);
- LineTo (XMAX -1, YMIN);
- PenPat (&qd.black);
- }
-
- //•-----------------------------------------------------------------•//
- void main ()
- {
- Rect myRect, trect;
-
- register i;
- register time;
- short x, xx, y, yy, xvel, yvel, xacc, yacc, ypos, offset;
- long waste;
- WindowPtr aWindow;
-
- InitGraf (&qd.thePort);
- InitWindows ();
-
- Hide_Menu_Bar ();
-
- Setup_Window ();
-
- OpenPort (&myPort); //o create my own port so I don't need.
- //o windows and can blacken the whole screen.
-
- HideCursor ();
-
- face.baseAddr = (Ptr) &facebits[0]; //o set up bitmap parameters.
- face.rowBytes = 2;
- SetRect (&face.bounds, 0, 0, 16, 16);
-
- Frame_It ();
-
- for (i = 0; i < 128; i++)
- {
- x = i << 3;
- if (x <= XMIN + 8 || x >= XMAX - 8)
- ground[i] = 0;
- else
- {
- ground[i] = BOT - 9;
- if (i & 01)
- if (ground[i - 1] == 0)
- ground[i] = 0;
- else
- ground[i] -= 7;
- }
- }
- //• Keep a tickin' while we ain't a clickin'!
- while (! Button ())
- {
- X_pos = Random () & 0177;
- if (ground[X_pos] <= TOP)
- {
- Delay (1L, &waste);
- continue;
- }
- x = X_pos << 3;
- xvel = 4 - ((Random () | 01) & 07);
- yacc = 1;
- yvel = 0;
- y = TOP;
- for (time = 0;; time++)
- {
- if (Button ()) //o Was a read key command.
- return;
-
- Draw_It (x, y);
- xx = x;
- yy = y; //o Save x and y.
- yvel += yacc;
- y += yvel;
- x += xvel;
-
- //o Bounce?
- if (y > ground[x >> 3])
- {
- if (yvel > 5)
- {
- Draw_It (xx, yy);
- Draw_It (x, y);
- Delay (1L, &waste);
- Draw_It (x, y);
- Draw_It (xx, yy);
- }
- //o Side collision?
- if (y <= ground[xx >> 3])
- {
- x = xx;
- xvel = -xvel;
- }
- else
- //o Bottom?
- if (yy <= ground[x >> 3])
- {
- y = yy;
- yvel = -yvel;
- }
- else
- { //o Corner.
- x = xx;
- y = yy;
- xvel = -xvel;
- yvel = -yvel;
- }
- if ((time & 017) == 0)
- xvel = Friction_Decay (xvel);
-
- if (xvel == 0)
- {
- X_pos = x >> 3;
- if (ground[X_pos - 1] <
- ground[X_pos] &&
- ground[X_pos] <
- ground[X_pos + 1])
- xvel = 1;
- //o Roll left.
- else
- if (ground[X_pos - 1] >
- ground[X_pos] &&
- ground[X_pos] >
- ground[X_pos + 1])
- xvel = -1;
- //o on hilltop.
- else
- if (ground[X_pos - 1] >
- ground[X_pos] &&
- ground[X_pos] <
- ground[X_pos + 1])
- {
- if (Random () & 01)
- xvel = 1;
- else
- xvel = -1;
- }
- } //o if xvel equals zero.
- yvel = Friction_Decay (yvel);
- }
- Delay (1L, &waste);
- Draw_It (xx, yy);
- if (xvel == 0 && yvel == 0 && y > ground[x >> 3]-4)
- break;
- } //o for time increments.
-
- for (;;)
- {
- //o find stable position.
- if (ground[X_pos - 1] < ground[X_pos] && ground[X_pos] > ground[X_pos + 1])
- {
- Draw_It (X_pos << 3, ground[X_pos]);
- ground[X_pos] -= 21;
- if (ground[X_pos - 1] <= 0)
- ground[X_pos] -= 7;
- ground[X_pos + 1] -= 7;
- break;
- }
- //o roll right.
- if (ground[X_pos - 1]<ground[X_pos] && ground[X_pos]<ground[X_pos+1])
- {
- X_pos++;
- continue;
- }
- //o roll left.
- if (ground[X_pos - 1] > ground[X_pos] && ground[X_pos] > ground[X_pos + 1])
- {
- X_pos--;
- continue;
- }
- //o on hilltop, choose at Random.
- if (ground[X_pos - 1] > ground[X_pos] && ground[X_pos] < ground[X_pos + 1])
- {
- if (Random () & 01)
- X_pos++;
- else
- X_pos--;
- continue;
- }
- //o else botch.
- Draw_It (X_pos << 3, ground[X_pos]);
- PaintRect (&myRect); //o was a call to f_rect ().
- break;
- } //o for ever.
- } //• while not button.
- Show_Menu_Bar ();
- }
-
- //•-----------------------------------------------------------------•//
- //• Show's over, folks!
- //•-----------------------------------------------------------------•//
-